{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 某场足球比赛，采取的是单场淘汰赛制，两两结队比赛，胜者进入下一轮，败者直接淘汰。如果队伍为奇数，则轮空的队伍直接进入下一轮。\n",
    "例如：\n",
    "如16只球队参赛，结成8对，赛8场，8只球队进入下一轮；再赛4场，4只球队晋级;再赛2场，2只球队晋级，2只胜利球队进行1场决赛决出冠军，两只失败球队进行1场3,4名决赛，决出3,4名。\n",
    "\n",
    "总的比赛场次为 8 + 4 + 2 + 1 + 1 = 16场比赛。\n",
    "\n",
    "如果队伍的数量为奇数同理：7只球队，结成3对，3个胜利者加一个轮空者进入下一轮，4只球队赛2场，2只胜利球队进行1场决赛决出冠军，两只失败球队进行1场3,4名决赛，决出3,4名。\n",
    "\n",
    "总的比赛场次为 3 + 2 + 1 + 1 = 7 场比赛。\n",
    "编写一个函数，输入任意的队伍数量，输出比赛场次：\n",
    "输入 32 输出 32\n",
    "输入 7 输出 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-25T11:23:25.979110Z",
     "start_time": "2022-01-25T11:23:25.970110Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "32"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def calc_games(teams:int)->tuple:\n",
    "    if teams % 2 == 0:\n",
    "        games = int(teams/2)\n",
    "        teams = int(teams/2)\n",
    "    else:\n",
    "        games = int((teams-1)/2)\n",
    "        teams = int((teams-1)/2 + 1)\n",
    "    return (games,teams)\n",
    "\n",
    "total_games = 0\n",
    "teams = 32\n",
    "while teams > 1:\n",
    "    games = calc_games(teams)[0]\n",
    "    total_games += games\n",
    "    teams = calc_games(teams)[1]\n",
    "total_games += 1\n",
    "total_games"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 根据Excel列表返回数字，升级版。\n",
    "这一次列标的长度不确定，可以是'AA','ZZA','ABCA','ABCAZ'.....长度不确定。\n",
    "编写一个函数，输入任意长度的列表返回列的序号。\n",
    "例如：输入'ZZ' 输出 702\n",
    "例如：输入'AAA' 输出 703\n",
    "例如：输入'AAZ' 输出 728\n",
    "Tips：不能使用晶晶已用过的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-25T11:32:44.268111Z",
     "start_time": "2022-01-25T11:32:44.244111Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "702"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "703"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "728"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string = 'ABCA'\n",
    "\n",
    "def calc_num(string:str)->int:\n",
    "    nums = 0\n",
    "    for index,letter in enumerate(string):\n",
    "        num = (ord(letter) - 64) * pow(26,(len(string)-1-index))\n",
    "        nums += num\n",
    "    return nums\n",
    "\n",
    "calc_num('ZZ')  \n",
    "calc_num('AAA')  \n",
    "calc_num('AAZ')  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-01-25T11:37:59.796911Z",
     "start_time": "2022-01-25T11:37:59.786911Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "28\n",
      "731\n",
      "19007\n"
     ]
    }
   ],
   "source": [
    "string = 'ABCA'\n",
    "nums = 0\n",
    "for letter in string:\n",
    "    nums = nums*26 + (ord(letter) -64)\n",
    "    print(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
